# -*- coding:utf-8 -*-
import datetime
import time



# 获取当前时间距离当天的24时还有多少秒，返回的数据类型为整形
def get_seconds():
    now = datetime.datetime.now()
    return int((datetime.datetime(now.year, now.month, now.day, 23, 59, 59) - now).total_seconds())


# 获取当前时间戳
def get_timestamp():
    return int(time.time())


# 时间戳转为标准格式
def conver_time(timestamp=1462451334):
    # 转换成localtime
    time_local = time.localtime(timestamp)
    # 转换成新的时间格式(2016-05-05 20:28:54)
    dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
    return dt


def getlatedate(i, str_date=''):
    if str_date == '':
        nowdate = datetime.date.today()  #
        tomorrow = nowdate + datetime.timedelta(days=i)
        return str(tomorrow)
    str_date = datetime.datetime.strptime(str_date, "%Y-%m-%d").date()
    tomorrow = str_date + datetime.timedelta(days=i)
    return str(tomorrow)


# 日期比较 返回值 为大的日期
def compare_date(str_date1, str_date2):
    str_date1 = str_date1.split(" ")[0]
    str_date2 = str_date2.split(" ")[0]
    str_date1 = datetime.datetime.strptime(str_date1, "%Y-%m-%d")
    str_date2 = datetime.datetime.strptime(str_date2, "%Y-%m-%d")
    if str_date1.date() >= str_date2.date():
        return str(str_date1.date())

    return str(str_date2.date())


def jq_sy_time(carIfon):
    insuranceType = carIfon.get("insuranceType", {})
    insuranceTime = carIfon.get("insuranceTime", {})
    syStart = ""
    jqStart = ""
    syEnd = insuranceTime.get("syEnd", "")
    jqEnd = insuranceTime.get("jqEnd", "")
    compulsoryInsurance = insuranceType.get("compulsoryInsurance", "0")
    endDate = carIfon.get("endDate", "")
    if compulsoryInsurance == "1" and jqEnd != "":
        jqStart = compare_date(jqEnd, getlatedate(1))
        # jqEnd = getlatedate(365, jqEnd)
    if compulsoryInsurance == "1" and jqEnd == "" and endDate != "":
        jqStart = compare_date(endDate, getlatedate(1))

    if syEnd != "":
        syStart = compare_date(syEnd, getlatedate(1))
        # syEnd = getlatedate(365, syEnd)
    else:
        syStart = compare_date(endDate, getlatedate(1))
    return {"syStart": syStart, "jqStart": jqStart}


if __name__ == "__main__":
    boy={
  "licenseNo": "苏MG3950",
  "vinNo": "LZWACAGA3B4195097",
  "endDate": "2017-06-20",
  "CCardDetail": "小型面包车",
  "CUsageCde": "",
  "insuredName": "靖江丽人妇产医院有限公司",
  "identifyNumber": "",
  "NNewPurchaseValue": "",
  "COMPANY_ID": "中国大地财产保险股份有限公司",
  "insuredAddress": "",
  "mobile": "",
  "enrollDate": "2011-10-17",
  "brandName": "五菱牌 LZW6376NF",
  "CModelCde": "",
  "insuranceType": {
    "otherHurtPremium": {
      "Amount": "500000.00",
      "isCheck": "1"
    },
    "driverDutyPremium": {
      "Amount": "10000.00",
      "isCheck": "1"
    },
    "passengerDutyPremium": {
      "Amount": "60000.00",
      "isCheck": "1"
    },
    "carDamagePremium": "1",
    "carFireBrokenBenchMarkPremium": "0",
    "carTheftPremium": "0",
    "otherHurtBenchMarkPremium": "0",
    "carTheftBenchMarkPremium": "0",
    "engineWadingBenchMarkPremium": "0",
    "JqSumPremium": "0",
    "carNickPremium": {
      "Amount": "0",
      "isCheck": "0"
    },
    "carDamageBenchMarkPremium": "0",
    "carNickBenchMarkPremium": "0",
    "engineWadingPremium": "0",
    "passengerBenchMarkPremium": "0",
    "SySumPremium": "1669.46",
    "driverDutyBenchMarkPremium": "0",
    "carFirePremium": "0",
    "glassBrokenPremium": "0",
    "compulsoryInsurance": "0",
    "nAggTax": "0"
  },
  "NSeatNum": "7",
  "engineNo": "B04135555",
  "insuranceTime": {
    "syEnd": "2017-06-20 00:00:00",
    "syStart": "2016-06-20 00:00:00",
    "jqStart": "",
    "jqEnd": ""
  }
}

    print jq_sy_time(boy)